
    <title>外包派送</title>


<div class="layui-fluid" style="padding: 15px">
    <div class="layui-card" style="padding-top: 10px">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" method="post" action="">
                    <div class="layui-row">
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">派送单号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <input type="text" name="deliverynumber" id="deliverynumber" autocomplete="off" placeholder="请输入" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">
                                <div class="layui-inline">
                                    <label class="layui-form-label">派送日期：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="deliveryDate" id="deliveryDate" lay-verify="date1"
                                               placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">车辆牌号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <select name="vehiclenumber" id="vehiclenumber"  lay-search="">
                                            <option value=""></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit
                                            lay-filter="formDemo">派送搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-row">
                    <table class="layui-hide" id="otherdeliverylist" lay-filter="otherdeliverylist"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="updotherdeliverylist">编辑</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table = layui.table;
        var $ = layui.jquery;
        //日期初始化
        form.render();

        /*车辆牌号下拉框赋值*/
        $.ajax({
            url:"../../selectOtherdeliverylist",
            success:function(data){
                for(var i =0;i<data.length;i++){
                    $("#vehiclenumber").append("<option value='"+data[i].vehiclenumber+"'>"+data[i].vehiclenumber+"</option>");
                    //重新渲染
                    form.render("select");
                }
            }
        });

        var tableIns=table.render({
            elem: '#otherdeliverylist'
            ,url:'../../queryOtherdeliverylist'
            ,title: '外包派送数据表'
            ,height:420
            ,cols: [[
                {field:'deliverynumber', title:'派送单号', width:160, sort: true}
                ,{field:'deliveryDate', title:'派送日期', width:170 }
                ,{field:'shippingnumber', title:'托运单号', width:170}
                ,{field:'arrivesubstation', title:'到达分站', width:170}
                ,{field:'driverName', title:'司机姓名', width:170}
                ,{field:'vehiclenumber', title:'车辆牌号', width:170}
                ,{field:'phonenumber', title:'手机号码', width:170}
                ,{field:'deliveryfee', title:'派送费用', width:170}
                ,{field:'operator', title:'操作员', width:170}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(otherdeliverylist)',function (obj) {
            switch (obj.event) {
                case 'updotherdeliverylist':
                    var deliverynumber=obj.data.deliverynumber;
                    updtherdeliveryDate(deliverynumber);
                    break;
                default:
                    break;
            }
        })

        /*表单提交*/
        form.on('submit(formDemo)', function(data){
            tableIns.reload({
                    type: 'post'
                    , url: '../../conditionqueryOtherdeliverylist',
                    where: {
                        //设定异步数据接口的额外参数，任意设
                        deliverynumber: data.field.deliverynumber
                        , deliveryDate: data.field.deliveryDate
                        , vehiclenumber: data.field.vehiclenumber
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });

            return false;
        });


        /*修改外包派送信息*/
        function updtherdeliveryDate(deliverynumber) {
            layui.use(['table','jquery','form'], function(){
                var form = layui.form;
                var table = layui.table;
                var $ = layui.jquery;
                $.ajax({
                    url : '../../getOtherdeliveryByid',
                    method : 'post',
                    data :{
                        deliverynumber:deliverynumber
                    } ,
                    dataType:"json",
                    success:function(data) {
                        updtherdeliverypopup();
                        setTimeout(function () {
                            //jquery获取内嵌框架对象
                            var updtherdelivery = $("#updtherdelivery").contents();
                            updtherdelivery.find("#deliverynumber").val(data.deliverynumber);
                            updtherdelivery.find("#deliveryDate").val(data.deliveryDate);
                            updtherdelivery.find("#shippingnumber").val(data.shippingnumber);
                            updtherdelivery.find("#arrivesubstation").val(data.arrivesubstation);
                            updtherdelivery.find("#driverName").val(data.driverName);
                            updtherdelivery.find("#vehiclenumber").val(data.vehiclenumber);
                            updtherdelivery.find("#phonenumber").val(data.phonenumber);
                            updtherdelivery.find("#deliveryfee").val(data.deliveryfee);
                            updtherdelivery.find("#operator").val(data.operator);
                        }, 500);
                    }
                });
            });
        }
        /*弹出层修改派送外包*/
        function updtherdeliverypopup(){
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    skin:'layui-layer-molv',//皮肤
                    content: '测试回调',
                    //大小
                    area:['90%', '650px'],
                    btn: [],
                    content: '<iframe src="updotherdelivery.html" id="updtherdelivery" width="100%" height="100%" frameborder="0"/>',
                    closeBtn: 2, //关闭按钮样式默认1
                    anim:4 //设置关闭动画
                });
            });
        }

        /* 表刷新方法 */
        function reloads(){
            layui.use('layer', function(){
                var table = layui.table;
                table.reload("otherdeliverylist");
            });
        }
    });
</script>